package com.technique.api.shop.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.technique.api.account.dao.PlaceRegisterDao;
import com.technique.api.dao.entity.Place;
import com.technique.api.dao.entity.PlaceExample;
import com.technique.api.dao.entity.PlaceRegister;
import com.technique.api.dao.entity.PlaceRegisterExample;
import com.technique.api.place.dao.PlaceDao;


@Service
public class ShopService {
	
	@Autowired
	private PlaceDao placeDao;

	@Autowired
	private PlaceRegisterDao placeRegisterDao;

	public List<Place> getRegisterPlace(long uid){
		PlaceRegisterExample example = new PlaceRegisterExample();
		example.createCriteria().andUserIdEqualTo(uid);
		List<PlaceRegister> list = this.placeRegisterDao.selectByExample(example);
		
		List<Long> ids = new ArrayList<Long>();
		for(PlaceRegister place: list){
			ids.add(place.getPlaceId());
		}
		
		PlaceExample placeExample = new PlaceExample();
		placeExample.createCriteria().andIdIn(ids);
		List<Place> placeList = placeDao.selectByExample(placeExample);
		
		return placeList;
	}
	
	public Map<Long,List<Long>> getRegisterShopByPlacesId(List<Long> placeIds){
		
		Map<Long,List<Long>> map = new HashMap<Long,List<Long>>();
		//1. 根据地区名称取用户列表
		for(Long placeId:placeIds){
			List<Long> list = new ArrayList<Long>();
			PlaceRegisterExample example = new PlaceRegisterExample();
			example.createCriteria().andPlaceIdEqualTo(placeId);
			List<PlaceRegister> registerList = this.placeRegisterDao.selectByExample(example);
			if(registerList!=null){
				for(PlaceRegister placeRegister:registerList){
					list.add(placeRegister.getUserId());
				}
			}
			map.put(placeId, list);
		}
		
		return map;
		
		
		
	}
	
}
